package com.zhouchb.test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Zhouchb
 * @Create 2021-11-2021/11/3 :22:26
 * @Description
 */
class haha{
    public static void main(String[] args) {
        Graph graph = new Graph(5);
        graph.addEdge(0,2);
        graph.addEdge(0,1);
        graph.addEdge(0,4);
        for (Object o : graph.getAdj(0)) {
            System.out.println(o);
        }

    }
}
public class Graph {
    private int vertex;//顶点
    private int edge;//边
    private List<Integer>[] adjacent;//邻接表

    public Graph(int vertex){
        this.vertex = vertex;
        this.edge = 0;
        this.adjacent = new List[vertex];
        for (int i=0;i<vertex;i++){
            adjacent[i] = new ArrayList<>();
        }
    }
    public void addEdge(int i,int j){
        adjacent[i].add(j);
        adjacent[j].add(i);
    }
    public List getAdj(int i){
        return adjacent[i];
    }
}
